package com.cloud.shopping.upload.qiniu;


import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author John.zhang
 * @version Id: QiNiuConfig, v 1.0 2020/12/28 15:50 ZhiYong Exp $
 */

@Component
@ConfigurationProperties(prefix = "qiniu")
public class QiNiuConfig {

    /**
     * accessKey
     */
    private String accessKey;

    /**
     * secretKey
     */
    private String secretKey;

    /**
     * 外链域名
     */
    private String host;

    /**
     * Bucket 识别符
     */
    private String bucket;

    /**
     * 空间类型
     */
    private String type;

    /**
     * 机房
     */
    private String zone;


    @Bean
    public UploadManager uploadManager() {
        Configuration configuration = new Configuration(Region.huadong());
        UploadManager uploadManager = new UploadManager(configuration);
        return uploadManager;
    }


    public String getToken() {
        Auth auth = Auth.create(accessKey, secretKey);
        return auth.uploadToken(bucket);
    }

}
